//index.js
//获取应用实例
const app = getApp()
const host = require('../../config').host

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    disableds:false,
    title:"",
    content:'',
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  userInput:function(e){
    // console.log(e)
    if(e.currentTarget.dataset.mark == "title"){
      this.setData({
        title:e.detail.value
      })
    }else if(e.currentTarget.dataset.mark == "content"){
      this.setData({
        content:e.detail.value
      })
    }
    
  },
  onLoad: function () {

  },
  submit: function(){
    var that = this
    if(!that.data.disableds){
      wx.showLoading({
        title: '正在提交中',
        mask: 'true'
      })
      var title = this.data.title
      var content = this.data.content
      var that = this;
      wx.request({
        url:host+'api/user/submit',
        data:{title:title,content:content,expert_id:app.globalData.id},
        success:function(res){
          // console.log(res.data.data.id)
          if(res.data.sta == 1){
            
            setTimeout(function () {
              wx.hideLoading()
            }, 1300)
            setTimeout(function () {
              wx.showToast({
               title:res.data.msg,
               icon:'success',
               duration:2000
             })
            }, 1300)
            wx.reLaunch({
              url: './index'
            })
            that.setData({
              disableds:false
            })
          }else if(res.data.sta == 2){
            setTimeout(function () {
              wx.hideLoading()
            }, 1500)
            setTimeout(function () {
                wx.showToast({
                 title:res.data.msg,
                 icon:'none',
                 duration:2000
               })
            }, 1500)
            
            that.setData({
              disableds:false
            })
          }
        },
        fail:function(){

        }
      })
    }
    that.setData({
      disableds:true
    })
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
